package com.lzh.service.impl;

import com.lzh.dao.QuesRes;
import com.lzh.pojo.entity.TgQuestion;
import com.lzh.pojo.resp.BaseResp;
import com.lzh.service.QuesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @author Li
 * @ 2022/4/7
 */
@Service
public class QuesServiceImpl implements QuesService {
    @Autowired
    QuesRes quesRes ;

    @Override
    public BaseResp find() {
        List<TgQuestion> list = quesRes.findAll();
        if (list!= null){
            return new BaseResp(1 , "查询成功" , list , null) ;
        }
        return new BaseResp(0 , "查询失败" , null , null) ;

    }

    @Override
    public BaseResp findById(Map map) {
        Object id = map.get("id");
        Integer integer = Integer.valueOf(id.toString());
        Optional<TgQuestion> byId = quesRes.findById(integer);
        if (byId!=null){
            return new BaseResp(1 , "查询成功" , byId.get() , null) ;
        }

        return new BaseResp(0 , "查询失败" , null , null) ;
    }
}
